﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Data.SQLite;

namespace sqliteTest
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {        
        public MainWindow()
        {
            InitializeComponent();

            testFunc();
           
        }

        public void testFunc() {

            SQLiteConnection myConnection = new SQLiteConnection();
            myConnection.ConnectionString = "Data Source=C:\\Users\\swssm\\data\\browser.db;";
            myConnection.Open();
            SQLiteCommand sqlcmd = new SQLiteCommand(myConnection);
            sqlcmd.CommandText = "select * from bookmarks;";            
            SQLiteDataReader reader = sqlcmd.ExecuteReader();          
            while (reader.Read())
            {                
                MessageBox.Show(reader["_id"] + " "
                    + reader["title"] + " " + reader["url"]);                
            }
            
            reader.Close();
            myConnection.Close();        
        }

    }

    public class AgeToColorConverter : IValueConverter
    {
        #region IValueConverter Members
        public object Convert(object value,
                                Type targetType,
                                object parameter,
                                System.Globalization.CultureInfo culture)
        {
            if (value is int)
            {
                int age = (int)value;
                if (age < 20) return "Orange";
                else if (age < 30) return "Red";
                else if (age < 40) return "Blue";
                else return "Gray";
            }
            return "Black";
        }
        public object ConvertBack(object value,
                                    Type targetType,
                                    object parameter,
                                    System.Globalization.CultureInfo culture)
        {
            return new NotSupportedException("ConvertBack is not supported");
        }
        #endregion
    }
}
